import java.util.*;
//JZ3 数组中重复的数字
public class Test {
    public int duplicate (int[] numbers) {
        //利用HashSet找出重复的数字,并返回
        if(numbers == null){
            return -1;
        }
        Set<Integer> set = new HashSet<>();
        for(int i = 0; i < numbers.length; i++){
            if(set.contains(numbers[i])){
                return numbers[i];
            }else{
                set.add(numbers[i]);
            }
        }
        return -1;
    }
    //JZ4 二维数组中的查找
    public boolean Find(int target, int [][] array) {
        //每一行进行二分查找
        for(int i = 0; i < array.length; i++){
            boolean flay = binarySearch(target, array[i]);
            if(flay){
                return true;
            }
        }
        return false;
    }
    public boolean binarySearch(int target, int[] array){
        int left = 0;
        int right = array.length - 1;
        while(left <= right){
            int mid = (left + right) / 2;
            if(target < array[mid]){
                right = mid - 1;
            }else if(target > array[mid]){
                left = mid + 1;
            }else{
                return true;
            }
        }
        return false;
    }
}
